import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;

import java.io.IOException;

//扫描整个表
public class ScanDemo {
    static Configuration conf = null;

    static {
        conf = HBaseConfiguration.create();
        conf.set("hbase.rootdir", "hdfs://192.168.126.139:9000/hbase");
        conf.set("hbase.master", "hdfs://192.168.126.139:60010");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        conf.set("hbase.zookeeper.quorum", "192.168.126.139");
    }

    public static ResultScanner queryByScan(String tableName) throws IOException {
        Scan scan = new Scan();
        HTable table = new HTable(conf, tableName);
        return table.getScanner(scan);
    }

    public static void main(String[] args) throws IOException {
        ResultScanner scanner = queryByScan("student");
        System.out.println("COLUMN\t\t\tCELL");
        for (Result result : scanner) {
            Cell[] cells = result.rawCells();
            for (Cell cell : cells) {
                System.out.print(new String(CellUtil.cloneFamily(cell)) + ":");
                System.out.print(new String(CellUtil.cloneQualifier(cell)) + "\t\t");
                System.out.print("value=" + new String(CellUtil.cloneValue(cell)) + ",");
                System.out.println("timestamp=" + cell.getTimestamp());
            }
        }
    }
}
